const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const IconsResolver = require('unplugin-icons/resolver')
const path = require('path')
const pathSrc = path.resolve(__dirname, 'src')
const isProd = process.env.NODE_ENV === 'production'
module.exports = {
  publicPath: isProd ? './' : '/',
  configureWebpack: {
    resolve: {
      alias: {
        components: '@/component'
      }
    },
    plugins: [
      AutoImport({
        import: ['vue'],
        resolvers: [
          ElementPlusResolver(),
          IconsResolver({
            prefix: 'Icon'
          })
        ],
        dts: path.resolve(pathSrc, 'auto-imports.d.ts')
      }),
      Components({
        resolvers: [
          ElementPlusResolver(),
          IconsResolver({
            enabledCollections: ['ep']
          })
        ],
        dts: path.resolve(pathSrc, 'components.d.ts')
      })
    ]
  },
  devServer: {
    host: 'localhost',
    https: false,
    hotOnly: false,
    port: 8090,
    proxy: {
      '^/api': {
        target: 'http://127.0.0.1:8080',
        pathRewrite: {
          '^/api': ''
        },
        changeOrign: true
      }
    }
  },
  pluginOptions: {
    electronBuilder: {
      nodeIntegration: true
    }
  }
}
